//
//  NSString+Extra.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/9/25.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "NSString+Extra.h"

@implementation NSString (Extra)

- (NSString *)timespToGMTFormat:(NSString *)format {
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"EEE MMM dd yyyy HH:mm:ss 'GMT'Z' (Coordinated Universal Time)'"];
    NSTimeZone * local = [NSTimeZone systemTimeZone];
    [formatter setTimeZone:local];
    [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
    NSDate * localDate = [formatter dateFromString:self];
    NSTimeInterval localTimeInterval = [localDate timeIntervalSinceReferenceDate];
    NSDate * localCurrentDate = [NSDate dateWithTimeIntervalSinceReferenceDate:localTimeInterval];
    [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    NSString *dateString = [formatter stringFromDate:localCurrentDate];
    return dateString;
}

- (NSString *)timespToUTCFormat:(NSString *)format {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter  setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"];
    NSDate *localeDate = [dateFormatter dateFromString:self];
    [dateFormatter  setTimeZone:[NSTimeZone localTimeZone]];
    [dateFormatter  setDateFormat:format];
    return [dateFormatter stringFromDate:localeDate];
}

- (NSString *)getAccountString {
    if ([self rangeOfString:@"digital"].location != NSNotFound) {
        return JFMainLocalizedString(@"digitalAccount");
    }else if ([self rangeOfString:@"jurisdiction"].location != NSNotFound) {
        NSString *string = [NSString stringWithFormat:@"%@Account", [[self substringFromIndex:self.length - 2] lowercaseString]];
        return JFMainLocalizedString(string);
    }
    return nil;
}

@end
